package com.drug.mingkang.controller;

import com.drug.mingkang.model.HqMarketdetail;
import com.drug.mingkang.model.vo.EChartsVo;
import com.drug.mingkang.model.vo.HqMarketDetailVo;
import com.drug.mingkang.model.vo.SalesStatisticsVo;
import com.drug.mingkang.permission.model.PerUsers;
import com.drug.mingkang.service.HqMarketdetailService;
import com.drug.mingkang.service.ImmSellService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.Map;

/**
 * 总公司销售明细(HqMarketdetail)表控制层
 *
 * @author wenchangjian
 * @since 2020-08-11 12:00:13
 */
@RestController
@RequestMapping("hqMarketdetail")
public class HqMarketdetailController {
    /**
     * 总公司销售明细服务对象
     */
    @Resource
    private HqMarketdetailService hqMarketdetailService;

    /**
     * 分公司销售明细服务对象
     */
    @Resource
    private ImmSellService immSellService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public HqMarketdetail selectOne(String id) {
        return this.hqMarketdetailService.queryById(id);
    }

    /**
     * 显示总公司所有销售
     * @param hqMarketDetailVo
     * @return
     */
    @ApiOperation(value = "显示总公司所有销售", notes = "显示总公司所有销售", httpMethod = "GET", response = Map.class)
    @GetMapping("showList")
    public Map<String,Object> showList(HqMarketDetailVo hqMarketDetailVo){
        return hqMarketdetailService.queryAllByLimit(hqMarketDetailVo);
    }

    /**
     * 根据年份查询总(分)公司销售前十销售量药品
     * @param page 页
     * @param limit 条
     * @param salesYear 年份
     * @param session 当前会话
     * @return
     */
    @ApiOperation(value = "根据年份查询总公司销售前十销售量药品", notes = "输入年份", httpMethod = "POST", response = Map.class)
    @PostMapping("selectMarketFrontShi")
    public List<EChartsVo> selectMarketFrontShi(Integer page, Integer limit, String salesYear, HttpSession session){
        PerUsers perUsers = (PerUsers)session.getAttribute("perUsers");
        if ("0".equals(perUsers.getCompanyId())) {
            return this.hqMarketdetailService.selectMarketFrontShi(page, limit, salesYear);
        }else{
            return this.immSellService.selectMarketFrontShi(page, limit, salesYear,perUsers.getCompanyId());
        }

    }

    /**
     * 根据年份查询总(分)公司 销售总金额与成本总金额对比图 与  销售总金额及毛利对比图 (实现销售量折线统计图)
     * @param salesYear 年份
     * @param session 当前会话
     * @return
     */
    @ApiOperation(value = "根据年份查询总(分)公司 销售总金额与成本总金额对比图 与  销售总金额及毛利对比图 (实现销售量折线统计图)",
            notes = "输入年份", httpMethod = "POST", response = Map.class)
    @PostMapping("findTotalCostAllPriceAndSalesProfit")
    public Map<String, Object> findTotalCostAllPriceAndSalesProfit(String salesYear, HttpSession session){
        PerUsers perUsers = (PerUsers)session.getAttribute("perUsers");
        if ("0".equals(perUsers.getCompanyId())) {
            return this.hqMarketdetailService.findTotalCostAllPriceAndSalesProfit(salesYear);
        }else{
            return this.immSellService.findTotalCostAllPriceAndSalesProfit(salesYear,perUsers.getCompanyId());
        }
    }

    /**
     * 根据年份查询总(分)公司 销售量数排行表(每年每月的总销售量)
     * @param salesStatisticsVo 销售量数排行表(每年每月的总销售量) Vo
     * @param status 状态（1 实现销量折线统计图的方法 2 实现销售排行统计表）
     * @param session 当前会话
     * @return
     */
    @ApiOperation(value = "根据年份查询总(分)公司 销售量数排行表(每年每月的总销售量)",
            notes = "输入年份", httpMethod = "POST", response = Map.class)
    @PostMapping("findAllSalesStatistics")
    public Map<String, Object> findAllSalesStatistics(SalesStatisticsVo salesStatisticsVo,String status ,HttpSession session){
        PerUsers perUsers = (PerUsers)session.getAttribute("perUsers");
        if ("0".equals(perUsers.getCompanyId())) {
            return this.hqMarketdetailService.findAllSalesStatistics(salesStatisticsVo,status);
        }else{
            //设置分公司Id
            salesStatisticsVo.setCompanyId(perUsers.getCompanyId());
            return this.immSellService.findAllSalesStatistics(salesStatisticsVo, status);
        }

    }


}